<?php
	/*
	 * File: subscribe_inc.php
	 * Last modification: 20.07.2011
	 * Author(s): kivio.wanderley
	 * 
	 */
?>
	
<?php /** UPPER PHP CODE */
	# Requires
	$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
	require_once($t_core_dir . 'core_api.php');

	# Try to make the connection
	if( !datab_is_connected() ) {
		config_get_global_array();
		datab_connect( config_get('host'), (int)config_get('port'), config_get('database'), 
					   config_get('user'), config_get('password') );
		config_unset();						   
	}
	
	# Start session
	if( ! isset($_SESSION) ) session_start();
	
	# Prepare variables
	require('subscribe_inc_vars.php');
	
	$t_type = gpc_get_string('subscribe_type');

?>

<?php  /** CENTER PHP CODE */
	if ( $t_type == 'user' ) { # For user subscribe
		/* Prepare password */
		$sub_pass = auth_anti_injection($sub_pass);
		$sub_pass = md5($sub_pass);
		$sub_pass = trim($sub_pass);
		$sub_pass = "'".$sub_pass."'";

		if( $sub_use_person == true) {
			/* Insert into user */
			datab_user_insert($people_option_list, $sub_user, $sub_pass, $sub_access_list );

		} elseif ( $sub_use_person == false ) {
			/* Insert into people */
			$peo_id = datab_people_insert($sub_cpf, $sub_first_name, $sub_last_name);
			/* Insert into user */
			datab_user_insert($peo_id, $sub_user, $sub_pass, $sub_access_list );
			
		} else { set_info_msg("ERRO ON CHECK FOR USER", I_ERR); }	
	
	} else {
		set_info_msg("NO TYPE FOR SUBSCRIBING", I_ERR);
	}
	
	//print_header_redirect( config_get('uri_prefix')."main_page.php?page=subscribe_page" );
	set_info_msg("SUBSCRIBE SAVE SUCCESS", I_OK, config_get('uri_prefix')."main_page.php?page=subscribe_page");
?>